<?php
/**
 * 账号
 *
 * @author kaikaic
 * @date 2018-04-09
 *
 */

namespace app\api\service;

use app\admin\service\AdvService;
use service\ConfigService;
use think\Db;

class   MecService{

    public static function getMecSet($id,$set_type){
        $imagearr =  ConfigService::getsetImage();
        if($set_type){
            $setList = Db::name('exam_set')->where('mec_id',$id)->where('status',1)->where('set_type',$set_type)->order('sort asc')->select();
        }else{
            $setList = Db::name('exam_set')->where('mec_id',$id)->where('status',1)->order('sort asc')->select();
        }
//        foreach ($setList as $key =>&$item){
//            $arr = array();
//            $item_ids = unserialize($item['item_ids']);
//            for ($i=0;$i<count($item_ids) ;$i++){
//                $deails = Db::name('exam_item e')
//                    ->join('exam_item_class ei','e.item_set_id = ei.id')
//                    ->field('e.name as ename,e.*,ei.* ')
//                    ->where('e.id',$item_ids[$i])->find();
//
//                $arr[$i]['name'] = $deails['ename'];
//                $arr[$i]['id'] = $deails['item_set_id'];
//                $arr[$i]['pname'] = $deails['name'];
//            }
//            $item['nameArr'] = $arr;
//            $item['icon'] = false;
//        }
        foreach ($setList as $key =>&$item){
            if($item['cover']){
                $item['set_image']=$item['cover'];
            }else{
                $setInfoarr = explode(',',$item['set_type']);
                $item['set_image']=$imagearr[$setInfoarr[0]];
                $item['setInfoarr']=$setInfoarr;
            }
        }
        return $setList;
    }
    public static function getRecomSet(){
        $imagearr =  ConfigService::getsetImage();

        $setList = Db::name('exam_set')->where('recommend',1)->where('status',1)->order('sort asc')->select();
//        foreach ($setList as $key =>&$item){
//            $arr = array();
//            $item_ids = unserialize($item['item_ids']);
//            for ($i=0;$i<count($item_ids) ;$i++){
//                $deails = Db::name('exam_item e')
//                    ->join('exam_item_class ei','e.item_set_id = ei.id')
//                    ->field('e.name as ename,e.*,ei.* ')
//                    ->where('e.id',$item_ids[$i])->find();
//
//                $arr[$i]['name'] = $deails['ename'];
//                $arr[$i]['id'] = $deails['item_set_id'];
//                $arr[$i]['pname'] = $deails['name'];
//            }
//            $item['nameArr'] = $arr;
//            $item['icon'] = false;
//        }
        foreach ($setList as $key =>&$item){
            if($item['cover']){
                $item['set_image']=$item['cover'];
            }else{
                $setInfoarr = explode(',',$item['set_type']);
                $item['set_image']=$imagearr[$setInfoarr[0]];
                $item['setInfoarr']=$setInfoarr;
            }
            $item['mecinfo']  = $mecres  = Db::name('exam_mec')
                ->field("id,name,recpoints")
                ->where('id',$item['mec_id'])
                ->find();
        }

        return $setList;
    }
    public static function getHighSet(){
        $imagearr =  ConfigService::getsetImage();

        $setList = Db::name('exam_set')->where('ishigh',1)->where('status',1)->order('sort asc')->select();

        foreach ($setList as $key =>&$item){
            if($item['cover']){
                $item['set_image']=$item['cover'];
            }else{
                $setInfoarr = explode(',',$item['set_type']);
                $item['set_image']=$imagearr[$setInfoarr[0]];
                $item['setInfoarr']=$setInfoarr;
            }
            $item['mecinfo']  = $mecres  = Db::name('exam_mec')
                ->field("id,name,recpoints")
                ->where('id',$item['mec_id'])
                ->find();
        }

        return $setList;
    }
    public static function getSettype($id){

        $res =  Db::name('system_category')->where('pid',$id)->select();
        return $res;
    }
}
